// 动态水生成
export class WaterPrimitive {
    constructor(options) {
        this._positions = options.positions;
        this._aper = options.aper;
        this._speedVal = options.speedVal
        this._height = options.height;
        this._textureCoordinates = options.textureCoordinates;
        this._extrudedHeight = options.extrudedHeight;
        this._targetHeight = Cesium.defaultValue(options.targetHeight, options.extrudedHeight);
        this._grow = Cesium.defaultValue(options.grow, false);
        console.log(this._grow)
        this._upGrow = Cesium.defaultValue(options.upGrow, true);
        console.log(this._upGrow)
        this.init();
    }
    getGeometry() {
        return new Cesium.PolygonGeometry({
            polygonHierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights(this._positions)),
            height: this._height,
            extrudedHeight: this._extrudedHeight,
            textureCoordinates: this._textureCoordinates,
            vertexFormat: Cesium.MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat
        });
    }
    update() {
        if (this._primitive) {
            let primitive = this._primitive;
            primitive.update(frameState);
        }
    }
    destroy() {
        let primitive = this._primitive;
        primitive.destroy()
    }
    init() {
        let geometry = this.getGeometry();
        if (!geometry) return;
        this._primitive = new Cesium.Primitive({
            releaseGeometryInstances: false,
            geometryInstances: new Cesium.GeometryInstance({
                geometry
            }),
            asynchronous: false,
            appearance: this._aper
        });
        if (this._grow) {
            this.grow();
        }
    }
    grow() {
        if (this._upGrow) {
            if (this.extrudedHeight < this._targetHeight) {
                this.extrudedHeight += this._speedVal;
                requestAnimationFrame(() => this.grow());
            }
        } else {
            if (this.extrudedHeight > this._targetHeight) {
                this.extrudedHeight -= this._speedVal;
                requestAnimationFrame(() => this.grow());
            }
        }
    }
}
Object.defineProperties(WaterPrimitive.prototype, {
    extrudedHeight: {
        get() {
            return this._extrudedHeight;
        },
        set(newVal) {
            // if (Object.prototype.toString.call(newVal) !== "[object Number]") return;
            if (typeof newVal !== 'number') return;
            if (this._primitive) {
                this._primitive._state = 3;
                this._primitive._appearance = undefined;
                this._primitive.geometryInstances.geometry = this.getGeometry();
                this._extrudedHeight = newVal;
            }
        }
    }
});
// WaterPrimitive.prototype.getGeometry = function () {
//     return new Cesium.PolygonGeometry({
//         polygonHierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights(this._positions)),
//         height: this._height,
//         extrudedHeight: this._extrudedHeight,
//         textureCoordinates: this._textureCoordinates,
//         vertexFormat: Cesium.MaterialAppearance.MaterialSupport.TEXTURED.vertexFormat
//     });
// };
// WaterPrimitive.prototype.update = function (frameState) {
//     if (this._primitive) {
//         let primitive = this._primitive;
//         primitive.update(frameState);
//     }
// };

// WaterPrimitive.prototype.destroy = function () {
//     let primitive = this._primitive;
//     primitive.destroy()
// }

// WaterPrimitive.prototype.init = function () {
//     let geometry = this.getGeometry();
//     if (!geometry) return;
//     this._primitive = new Cesium.Primitive({
//         releaseGeometryInstances: false,
//         geometryInstances: new Cesium.GeometryInstance({
//             geometry
//         }),
//         asynchronous: false,
//         appearance: this._aper
//     });
//     if (this._grow) {
//         this.grow();
//     }
// };
// WaterPrimitive.prototype.grow = function () {
//     if (this._upGrow) {
//         if (this.extrudedHeight < this._targetHeight) {
//             this.extrudedHeight += this._speedVal;
//             requestAnimationFrame(() => this.grow());
//         }
//     } else {
//         if (this.extrudedHeight > this._targetHeight) {
//             this.extrudedHeight -= this._speedVal;
//             requestAnimationFrame(() => this.grow());
//         }
//     }
// }
// Cesium.WaterPrimitive = WaterPrimitive;